using Game.Main.Model;
using Game.XH;
using UnityEngine;

namespace Game.Component
{
	public class FaceMaskItem : BaseItem
	{
		private enum State
		{
			State1 = 0,
			State2 = 1
		}

		private State state;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		public override void ResetState()
		{
			base.ResetState();
			CheckState();
		}

		private void CheckState()
		{
			if (parentItem != null && typeof(CharacterItem).IsAssignableFrom(parentItem.GetType()))
			{
				SetState(State.State2);
			}
			else
			{
				SetState(State.State1);
			}
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			base.TouchDown(touchEventData);
			SetState(State.State2);
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			base.TouchUp(touchEventData);
			CheckState();
		}

		private void SetState(State val)
		{
			if (state != val)
			{
				state = val;
				if (state == State.State1)
				{
					model.GetComponent<SpriteRenderer>().enabled = true;
					model.Find("DragModel").SetObjectActive(false);
				}
				else
				{
					model.GetComponent<SpriteRenderer>().enabled = false;
					model.Find("DragModel").SetObjectActive(true);
				}
			}
		}
	}
}
